package com.hotel.controller;

import com.hotel.common.AjaxResult;
import com.hotel.domain.service.RecordInfoService;
import com.hotel.pojo.Record;
import com.hotel.pojo.RecordInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/recordInfo")
public class RecordInfoController {

    @Autowired
    private RecordInfoService recordInfoService;

    /**
     * 获取住房记录详细信息列表
     * @param recordInfo 详细入住记录对象
     * @param page 页码
     * @param perPage 每页的条数
     * @return AjaxResult
     */
    @GetMapping("/{page}/{perPage}")
    @ResponseBody
    public AjaxResult getRecordInfoList(RecordInfo recordInfo, @PathVariable("page") int page, @PathVariable("perPage") int perPage){
        System.out.println(recordInfo);
        System.out.println(page + "" + perPage);
        return AjaxResult.queryAjax(recordInfoService.getRecordInfoList(recordInfo, page, perPage));
    }

    /**
     * 更新住房详细信息
     * @param recordInfo 详细入住记录对象
     * @return AjaxResult
     */
    @PostMapping("/update")
    @ResponseBody
    public AjaxResult updateRecordInfo(@RequestBody RecordInfo recordInfo){
        return AjaxResult.updateAjax(recordInfoService.updateRecordInfo(recordInfo));
    }

    /**
     * 入住登记
     * @param recordInfos 详细记录信息对象数组
     * @return AjaxResult
     */
    @PostMapping("/checkIn")
    @ResponseBody
    public AjaxResult checkIn(@RequestBody RecordInfo[] recordInfos){
        return AjaxResult.updateAjax(recordInfoService.checkIn(recordInfos));
    }

    /**
     * 逻辑删除入住记录
     * @param id 记录ID
     * @return AjaxResult
     */
    @PostMapping("/delete")
    @ResponseBody
    public AjaxResult deleteRecordInfo(@RequestBody int id){
        //新建Record对象，将逻辑删除属性设置为1
        RecordInfo recordInfo = new RecordInfo();
        recordInfo.setRecordDel(1);
        recordInfo.setRecordId(id);
        //更新入住记录
        return AjaxResult.updateAjax(recordInfoService.updateRecordInfo(recordInfo));
    }

}
